nextchildid=1;
childlist=new Array();

function ChildWin(obj,type)
{
 this.name=window.name+'_'+type+'_'+nextchildid;
 obj.name=this.name;
 obj.name1=this.name;
 nextchildid++;
 this.obj=obj;
 this.type=type;
}

function AddChild(obj,type)
{
 var i=0;
 while (childlist[i])
  i++;
 childlist[i]=new ChildWin(obj,type);
}

function RemoveChild(name,close)
{
 var i;
 for (i=0;i<childlist.length;i++)
  if (childlist[i] && childlist[i].name==name)
  {
   if (close)
    childlist[i].obj.close();
   delete childlist[i];
   childlist[i]=0;
  }
}

function EnumChildren(funct,type,param)
{
 var j=childlist.length;
 var i;
 var ret=false;
 for (i=0;i<j;i++)
 {
  if (!childlist[i] || type && type!='all' && childlist[i].type!=type)
   continue;
  ret=funct(childlist[i].obj,param);
  if (ret)
   break;
 }
 return ret;
}

function winclose(obj,param)
{
 if (param)
  obj.opener=obj;
 obj.close();
}

function CloseChildren(type,selfclosed)
{
 EnumChildren(winclose,type,selfclosed);
}

function isfree(obj)
{
 if (obj.winlocked || obj.GetLockedChild && obj.GetLockedChild())
   return 0;
 return obj;
}

function GetFreeChild(type)
{
 return EnumChildren(isfree,type);
}

function isnotfree(obj)
{
 if (obj.winlocked || obj.GetLockedChild && obj.GetLockedChild())
   return obj;
 return 0;
}

function GetLockedChild(type)
{
 return EnumChildren(isnotfree,type);
}

function findwin(obj,name)
{
 if (!name || obj.name==name)
  return obj;
 else if (obj.FindWindow)
  return obj.EnumChildren(findwin1,'',name);
 return 0;
}

function findwin1(obj,name)
{
 if (obj.name==name)
  return obj;
 else if (obj.FindWindow)
  return obj.EnumChildren(findwin,'',name);
 return 0;
}

function FindWindow(name)
{
 return EnumChildren(findwin,'',name);
}
